package com.yhy.api.api;


import cn.hutool.json.JSONUtil;
import com.yhy.api.model.User;
import com.yhy.common.core.model.ContextUser;
import com.yhy.common.core.result.Result;
import com.yhy.common.core.utils.ContextUtil;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Slf4j
@RestController
@RequestMapping("/feign")
@RequiredArgsConstructor
public class TestFeign {

    @ApiOperation("测试feign")
    @PostMapping("/test1")
    public Result<?> test(@RequestBody User user) {
        log.info("测试日志");
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        executorService.submit(() -> log.info("异步日志"));
        log.info("当前用户: {}", JSONUtil.toJsonStr(ContextUtil.getUser()));
        return Result.ok("test-result + " + user.getId());
    }

    @ApiOperation("test接口1")
    @GetMapping("/test2")
    public Result<ContextUser> test1(@RequestParam("param") String param) {
        log.info("主线程日志");
        return Result.ok(ContextUtil.getUser());
    }

}
